package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.autoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 分页查询
     *
     * @param dishPageQueryDTO
     * @return
     */
    
    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 新增菜品
     * @param dish
     * @return
     */
    @autoFill(value = OperationType.INSERT)
    void save(Dish dish);

    /**
     * 通过菜品ID查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id=#{id}")
    Dish selectById(Long id);

    /**
     * 批量删除dish
     * @param ids
     */
    void deletByIds(List<Long> ids);

    /**
     * 修改菜品的起售与停售
     * @param status
     */
//    @autoFill(value = OperationType.UPDATE)
    @Update("update dish set status=#{status} where id =#{id} ")
    void updateStatus(Long status,Long id);

    /**
     * 更新菜品基本信息
     * @param dish
     */
    @autoFill(value = OperationType.UPDATE)
    void update(Dish dish);
    /**
     * 根据分类id查询菜品
     *
     */
    @Select("select * from dish where category_id=#{id} ")
    List<Dish> list(Long id);
}
